<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>&nbsp;</title>
<link rel="stylesheet" href="./css/login.css">

</head>
<body>

    <div class="LoginBox" id="adminLogin">
        <div class="VerticalCenteredBox" style="height: 300px;">
            <div class="LoginHead">
                                             流浪动物救助平台
            </div>
            <div class="LoginUserBoxOut ">
                <span>账号：</span>
                <div class="LoginUserBox">
                    <input class="LoginUserInput" type="text" v-model.trim="username" />
                </div>
            </div>
            <div class="LoginUserBoxOut">
                <span>密码：</span>
                <div class="LoginUserBox">
                    <input class="LoginUserInput" type="password" v-model.trim="password"/>
                </div>
            </div>
            <div class="LoginUserBoxOut" style="display: none">
                    <input type="radio" checked="checked"/>0&nbsp;&nbsp;&nbsp;
				    <input type="radio" />1&nbsp;&nbsp;&nbsp;
            </div>
            <div class="LoginUserBoxOut">
                <div class="LoginLastBox clearfix">
                    <a href="javascript:;" @click="userLogin()">
                        <div class="RightBox">登录</div>
                    </a>
                </div>
            </div>

        </div>
    </div>

<script type="text/javascript" src="/js/vue.min.js"></script>
<script type="text/javascript" src="/js/axios.min.js"></script>

<script type="text/javascript">
     var vm = new Vue({
		
		el: '#adminLogin',
		data: 
		{
			username:"",
			password:"",
		},
		methods: 
		{
			userLogin()
			{
				if(this.username=="")
				{
					alert("请输入账号");
					return;
				}
				if(this.password=="")
				{
					alert("请输入密码");
					return;
				}
				axios({
						method: 'POST',
						url: '/adminLogin',
						params:{
							username:this.username,
							password:this.password,
						}
						}).then(data => {
							//console.log(data);
							if (data.data.state == 66)
							{
								alert("登录成功");
								var admin=data.data.data;
								localStorage.setItem("admin",JSON.stringify(admin));//吧admin对象转成json格式数据，然后存储到localStorage
								
								location.href="/admin/index.html";
							} 
						    if (data.data.state == 45)
							{
								alert("账号错误");
							}
							if (data.data.state == 46)
							{
								alert("密码错误");
							}
						}).catch(error => {
							//console.log(error);
							alert(error);
						})
			}
		}
	    
	
	})

	
	/* 在vue的生命周期函数create（）中获取user信息 */
	/* var userJsonString = localStorage.getItem("user");*/
	/* var user=JSON.parse(userJsonString)//转成user对象 */

</script>

</body>	
</html>
